package org.example.oauth2.service;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.common.util.StringPool;
import org.example.oauth2.constant.AuthConstant;
import org.example.oauth2.entity.User;
import org.springframework.core.env.Environment;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 用户信息
 */
@Service
@AllArgsConstructor
@Slf4j
public class TdiiUserDetailsServiceImpl implements UserDetailsService {


    private final Environment environment;


    @Override
    @SneakyThrows
    public UserDetails loadUserByUsername(String username) {
        User user = new User("ad","admin", "21b4e1f8e4f1a7d545fecfe2efeefb5f872cdfff", "ss", "ssss",
                              "sss", "ss", null,null,1,
                null,null);

        String grantedAuthority = "administrator";
        List<GrantedAuthority> grantedAuthorities = AuthorityUtils.commaSeparatedStringToAuthorityList(grantedAuthority);
        return new CustomUserDetails(1L,
                StringPool.EMPTY, user.getName(), user.getRealName(), user.getDeptId(), user.getRoleId() ,user.getRealName(), user.getAvatar(),
                user.getAccount(), AuthConstant.ENCRYPT + user.getPassword(), true, true,
                true, true,
                grantedAuthorities, "abc");

    }

}
